<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "cdn_config".
 *
 * @property-read array $classArray
 * @property-read array $statusTexts
 * @property string $class 存储名称
 * @property string $appId appId
 * @property string $accessKey accessKey
 * @property string $accessSecret accessSecret
 * @property string $bucket 存储空间(bucket)
 * @property string $endPoint 存储节点(endPoint)
 * @property string $host 存储域名(host)
 * @property int $status 状态
 */
class CdnConfig extends BaseModels
{

    const QiNiu = 'feehi\cdn\QiniuTarget';
    const AliOSS = 'feehi\cdn\AliossTarget';
    const QCloud = 'feehi\cdn\QcloudTarget';
    const NetEase = 'feehi\cdn\NeteaseTarget';

    /**
     * @var array
     */
    public $classArray = [
        self::QiNiu   => '七牛云',
        self::AliOSS  => '阿里云',
        self::QCloud  => '腾讯云',
        self::NetEase => '网易云'
    ];

    /**
     * @var array
     */
    public $statusTexts = [
        0 => '禁用',
        10 => '启用',
    ];

    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'cdn_config';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['class','accessKey','accessSecret','bucket','host'], 'required'],
            [['status'], 'integer'],
            [['class', 'appId', 'accessKey', 'bucket'], 'string', 'max' => 100],
            [['accessSecret', 'host'], 'string', 'max' => 255],
            [['endPoint'], 'string', 'max' => 50],
            [['class'], 'unique'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'class' => '存储名称',
            'appId' => 'appId',
            'accessKey' => 'accessKey',
            'accessSecret' => 'accessSecret',
            'bucket' => '存储空间(bucket)',
            'endPoint' => '存储节点(endPoint)',
            'host' => '存储域名(host)',
            'status' => '状态',
        ];
    }


    /**
     * findActive
     * @return array
     */
    public static function findActive()
    {
        $model = self::findOne(['status'=>10]);
        return !empty($model)?$model->toArray():[];
    }

}
